//
//  HLSessionUntils.m
//  YueYue
//
//  Created by hulu001 on 2023/6/12.
//

#import "HLSessionUntils.h"

@implementation HLSessionUntils

+ (NSString *)tipOnMessageRevoked:(NIMRevokeMessageNotification *)notification
{
    NSString *tip = @"";
    do {
        if (!notification || ![notification isKindOfClass:[NIMRevokeMessageNotification class]]) {
            tip = @"你";
            break;
        }
        tip = [self tipTitleFromMessageRevokeNotificationP2P:notification];
    } while (false);
    
    NSString *msg = @"对方撤回了一条消息";
    if (notification.postscript.length != 0) {
        msg = [NSString stringWithFormat:@"对方撤回了一条消息.附言:%@,%@", tip, notification.postscript];
    }
    return msg;
}

+ (NSString *)tipTitleFromMessageRevokeNotificationP2P:(NIMRevokeMessageNotification *)notification {
    NSString *fromUid = notification.messageFromUserId;
    BOOL fromMe = [fromUid isEqualToString:[[NIMSDK sharedSDK].loginManager currentAccount]];
    return fromMe ? @"你" : @"对方";
}

+ (NSDictionary *)setKeyValue:(NSDictionary *)keyValue toLocalExt:(NSDictionary *)localext
{
    NSMutableDictionary *localExt = nil;
    
    if (localext) {
        localExt = [NSMutableDictionary dictionaryWithDictionary:localext];
    } else {
        localExt = [NSMutableDictionary dictionary];
    }
    
    [localExt addEntriesFromDictionary:keyValue];
    
    return localExt;
}

+ (NSDictionary *)removeKey:(NSString *)key toLocalExt:(NSDictionary *)localext
{
    NSMutableDictionary *localExt = nil;
    
    if (localext) {
        localExt = [NSMutableDictionary dictionaryWithDictionary:localext];
        [localExt removeObjectForKey:key];
    }
    
    return localExt;
}

+ (NSAttributedString *)attributedTipWithPrice:(NSString *)price
{
    NSMutableAttributedString *attributedText = [NSMutableAttributedString.alloc init];
    [attributedText appendAttributedString:[NSAttributedString.alloc initWithString:@"文字聊天" attributes:@{NSFontAttributeName:UIFontMake(12), NSForegroundColorAttributeName:[UIColor qmui_colorWithHexString:@"#63637F"]}]];
    [attributedText appendAttributedString:[NSAttributedString.alloc initWithString:[NSString stringWithFormat:@"%@金币/条", price] attributes:@{NSFontAttributeName:UIFontMake(12), NSForegroundColorAttributeName:[UIColor qmui_colorWithHexString:@"#FB0037"]}]];
    
    return attributedText;
}

+ (NSAttributedString *)maleChatCardTipWithAvaliableCount:(NSString *)count
{
    NSMutableAttributedString *attributedText = [NSMutableAttributedString.alloc init];
    [attributedText appendAttributedString:[NSAttributedString.alloc initWithString:[NSString stringWithFormat:@"当前聊天卡可用%@张", count?:@"0"] attributes:@{NSFontAttributeName:UIFontMake(12), NSForegroundColorAttributeName:[UIColor qmui_colorWithHexString:@"63637F"]}]];
    
    return attributedText;
}

+ (NSAttributedString *)maleNoMoneyTip
{
    NSMutableAttributedString *attributedText = [NSMutableAttributedString.alloc init];
    [attributedText appendAttributedString:[NSAttributedString.alloc initWithString:@"金币不足，" attributes:@{NSFontAttributeName:UIFontMake(12), NSForegroundColorAttributeName:[UIColor qmui_colorWithHexString:@"#63637F"]}]];
    [attributedText appendAttributedString:[NSAttributedString.alloc initWithString:@"立即充值" attributes:@{NSFontAttributeName:UIFontMake(12), NSForegroundColorAttributeName:[UIColor qmui_colorWithHexString:@"#FB0037"]}]];
    
    return attributedText;
}

@end
